package com.example.androidtest;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import android.R.bool;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Message;

public class ImageThread extends Thread{
	private Handler handler;
	private URL u;
	public ImageThread(Handler handler,String string){
		this.handler = handler;
		try {
			u = new URL(string);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@Override
	public void run() {
		try {
			HttpURLConnection connection = (HttpURLConnection) u.openConnection();
			connection.connect();
			InputStream is = connection.getInputStream();
			Bitmap bitmap = BitmapFactory.decodeStream(is);
			is.close();
			connection.disconnect();
			Message msg  = new Message();
			msg.what = 200;
			msg.obj = bitmap;
			handler.sendMessage(msg);
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
